{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "4c52df3c",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "from scipy.optimize import minimize"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "61b2f463",
   "metadata": {},
   "outputs": [],
   "source": [
    "def func(x):\n",
    "    return x[0] ** 2 + (x[0] + x[1]) ** 3 + (x[0]*x[1]) ** 2 + x[1] + x[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "63127c08",
   "metadata": {},
   "outputs": [],
   "source": [
    "def grad(x):\n",
    "    return np.array([2 * x[0]+3 * (x[0] + x[1]) ** 2 + 2 * x[1] ** 2 * x[0],3 * (x[0] + x[1]) ** 2 + 2 * x[1] * x[0] ** 2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "85ae6030",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "  message: Desired error not necessarily achieved due to precision loss.\n",
       "  success: False\n",
       "   status: 2\n",
       "      fun: -289168613167.2922\n",
       "        x: [ 7.313e+02  7.313e+02]\n",
       "      nit: 1\n",
       "      jac: [-7.887e+08 -7.887e+08]\n",
       " hess_inv: [[ 5.000e-01 -5.000e-01]\n",
       "            [-5.000e-01  5.000e-01]]\n",
       "     nfev: 348\n",
       "     njev: 112"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "minimize(func, [0, 0])"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.18"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
